package com.example.myapplication;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.utils.Utils;

public class LayoutActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout);

        TextView tv = findViewById(R.id.text_view);
        ViewGroup.LayoutParams layoutParams = tv.getLayoutParams();

        layoutParams.width = Utils.dip2px(this, 300);  // unit: px
        tv.setLayoutParams(layoutParams);
    }
}